import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        username: '',
        cname:'',
        tagLabel: []
    },
    mutations: {
        saveUsername(state, name) {
            state.username = name
        },
        saveUserCname(state, cname) {
            state.cname = cname
        },
        //添加tag标签
        addTagLabel(state, tagObj) {

            console.log(tagObj);
            let i = 0
            for (; i < state.tagLabel.length; i++) {
                if (state.tagLabel[i].name == tagObj.name) {
                    break;
                }
            }
            if (i == state.tagLabel.length) {
                state.tagLabel.push(tagObj)
            }

        },
        removeTagLabel(state, tagObj) {
            let i = 0
            for (; i < state.tagLabel.length; i++) {
                if (state.tagLabel[i].name == tagObj.name) {
                    state.tagLabel.splice(i, 1);
                }
            }
        },
        clearAllTagLabel(state){
            state.tagLabel=[]

        }
    }
})


export default store
